package com.oocl.customer.servlet;

import java.io.IOException;
import java.net.ConnectException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.customersystem.dto.Food;
import com.oocl.customersystem.dto.MUserFoodList;
import com.oocl.customersystem.service.FoodManager;
import com.oocl.customersystem.service.MUserFoodManager;
import com.oocl.customersystem.service.impl.FoodManagerImpl;
import com.oocl.customersystem.service.impl.MuserFoodManagerImpl;
import com.oocl.customersystem.util.RequestUtil;

public class ShowFood extends BaseServlet{
	
	public void showFoodByType(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {		
		FoodManager manager=new FoodManagerImpl();
		String uri="http://ZHA-ITA092-W7:8089/merchantv2/foodlist2c";
		String mId=request.getParameter("mid");
		String fType=request.getParameter("ftype");
		String par="mid="+mId+"&ftype="+fType;
		try {
			List<Food> fList=manager.getFoods(uri, par);
			request.setAttribute("flist", fList);		
			request.getRequestDispatcher("showFoodByType.jsp").forward(request, response);
		} catch (ConnectException e) {
			request.getRequestDispatcher("error.jsp").forward(request, response);//连接出错
		}		
	}
	
	public void showFoodByMerchant(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		MUserFoodManager manager=new MuserFoodManagerImpl();

		
		String uri="http://10.222.29.187:8089/merchant/foodlist2c";      //向C端发送拿菜品消息
	
		String mId=request.getParameter("mid");
		mId="mid="+mId;
		
		try {
			MUserFoodList mufl=manager.getMUserFoodList(uri, mId);	
			if (mufl.getmUser()!=null) {
				request.setAttribute("mufl", mufl);
				request.getRequestDispatcher("showFoodByMerchant.jsp").forward(request, response);//转到显示改商家所有菜品信息
			}
		} catch (ConnectException e) {
			request.getRequestDispatcher("error.jsp").forward(request, response);//连接出错
		}
		
		
	
		
	}

}
